package BookStore.dao;

import BookStore.model.Vip;
import BookStore.util.VDbUtil;
import BookStore.view.A_VIP;

import javax.swing.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


public class VipDao {
    private Vip vip;

    public VipDao(Vip temp) {
        this.vip = temp;
    }
    public void register_2() throws Exception {
        Connection con_2 = VDbUtil.getCon_2();
        System.out.println(vip.toString());
        String sql5 = "select * from VIP where vid = '" + vip.getVipId() + "' ";
        PreparedStatement ps = con_2.prepareStatement(sql5);
        ResultSet result_2 = ps.executeQuery();
        if (result_2.next()) {
            JOptionPane.showMessageDialog(null,"该会员已存在");
        } else{
            String sql6 = "insert into VIP (vid,name,sex,tel,lev,discount,cost) values ('" + vip.getVipId() + "','" + vip.getVipName() + "','" + vip.getVipSex() + "','" +
                   vip.getVipTel()+ "','" + vip.getVipLev() + "','" + vip.getVipDiscount() + "','"+vip.getVipCost()+"')";
            ps = con_2.prepareStatement(sql6);
            int count = ps.executeUpdate();
            JOptionPane.showMessageDialog(null,"会员添加成功");
            new A_VIP().setVisible(true);
        }
        con_2.close();
        ps.close();
    }

}

